import javax.swing.*;
import java.util.Random;

public class DrawTime {
    public static void main(String[] args){
        Random random=new Random();
        MyTime myTimer=new MyTime(random.nextInt(24),random.nextInt(60),random.nextInt(60));
        DrawPanel_new panel=new DrawPanel_new(new MyTime[]{myTimer});
        JFrame application = new JFrame();
        application.setTitle("随机生成的时间并开始运行");
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        application.add(panel);
        application.setSize(400, 400);
        application.setVisible(true);
        Thread t = new Thread() {
            public void run() {
                while (true) {
                    try {
                        Thread.sleep(1000); //设置绘制的时间间隔为 1 秒
                    } catch (InterruptedException e) {
                        System.err.println(e);
                    }
                    myTimer.incrementSecond();//更新绘制图形面板上的内容（也就是绘制的图像）
                    panel.updateUI();
                }
            }
        };
        t.start();
    }
}
